//
//  SelectionCell.m
//  ComboBox
//
//  Created by Eric Che on 7/17/13.
//  Copyright (c) 2013 Eric Che. All rights reserved.
//

#import "SelectionCell.h"
#import "CAccountModel.h"
#import "UIImageView+WebCache.h"
#import "CXmppRequestMgr.h"

@interface SelectionCell ()

@property (weak, nonatomic) IBOutlet UILabel *lb;
@property(weak, nonatomic) IBOutlet UIView *line;
@property(weak, nonatomic) IBOutlet UIImageView *headerImgView;
@property (weak, nonatomic) IBOutlet UIButton *deleteBtn;
- (IBAction)deleteBtnClicked:(UIButton *)sender;



@end

@implementation SelectionCell


- (void)setAccount:(CAccountModel *)account
{
    _account = account;
    self.lb.text = account.loginName;
    [self.headerImgView sd_setImageWithURL:[NSURL URLWithString:[[CXmppRequestMgr shareInstance] DownHeadFileWithContact:account.userId]] placeholderImage:[UIImage imageNamed:@"defaultHeaderImage"]];

}

-(void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat rate = 1.0f;
    if(HARDWARE_SCREEN_HEIGHT >= 736)
    {
        //        rate = 1.30f;
    }
    
    CGRect frame  = self.frame;
    frame.size.height = frame.size.height*rate;
    self.frame = frame;
    
    self.headerImgView.frame = CGRectMake(10.0f, 7.0f, 30.0f, 30.0f);
    
    self.lb.frame = CGRectMake(CGRectGetMaxX(self.headerImgView.frame) + 10.0f, 0, self.width - 20.0f - CGRectGetMaxX(self.headerImgView.frame) - 20.0f, self.height);
    self.lb.font = [UIFont systemFontOfSize:15];
//    UIFont *font = self.lb.font;
//    self.lb.font = [UIFont systemFontOfSize:font.pointSize*rate];
    self.deleteBtn.frame = CGRectMake(CGRectGetMaxX(self.lb.frame), self.lb.center.y - 15, 30 , 30);
    self.line.frame = CGRectMake(OppositeWidthRate(10), self.height - 0.5, self.width - 2 * OppositeWidthRate(10), 0.5);
    
    
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)delActon:(id)sender
{
    if(self.delDelegate && [self.delDelegate respondsToSelector:@selector(delItem:)])
    {
        [self.delDelegate delItem:[self.lb.text stringByReplacingOccurrencesOfString:@"@" withString:@"_"]];
    }
}

- (IBAction)deleteBtnClicked:(UIButton *)sender {
    if(self.delDelegate && [self.delDelegate respondsToSelector:@selector(delItem:)])
    {
        [self.delDelegate delItem:[self.lb.text stringByReplacingOccurrencesOfString:@"@" withString:@"_"]];
    }

}
@end
